package com.lmm.rpc.core.handler;

import com.lmm.rpc.core.client.protocol.MessageProtocol;
import com.lmm.rpc.core.common.reponse.DefaultRepose;
import com.lmm.rpc.core.transport.LocalRpcResponseCache;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * 数据响应处理器
 *
 * ChannelInboundHandler - 处理进站数据
 * 注意 SimpleChannelInboundHandler 会自动释放资源，而无需存储任何信息的引用。
 * */
@ChannelHandler.Sharable
public class DefaultResponseHandler extends SimpleChannelInboundHandler<MessageProtocol<DefaultRepose>> {
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, MessageProtocol<DefaultRepose> defaultReposeMessageProtocol) throws Exception {
        LocalRpcResponseCache.fillResponse(String.valueOf(defaultReposeMessageProtocol.getHeader().getRequestId()),defaultReposeMessageProtocol);
    }
}
